Ask a Question
Send an email to me.
 
Java Question and Answer Forums
JavaRanch Big Moose Saloon
Marcus Green's Discussion Forum
java.sun.com Forums, Chat and User Groups
Artima Java Answers Forum
 
Other Resources
Java Language Specification
Java Virtual Machine Specification
Java 2 Platform, Standard Edition, v 1.4.0 API Specification
 
Tutorials
Learning the Java Language
Operator Precedence Chart, Expressions, Statements, Blocks
Programming with Assertions
 
Answers: Certified Java Programmer Mock Exam
No.AnswerRemark
1c  Compile-time error.  An anonymous class is not permitted to declare a constructor.  
2b  c  d  2  3  4  An abstract method has no implementation and is not useful until an extending class implements the method. A final class can not be overridden by a subclass method. An abstract final method can not be implemented and is not legal. An abstract class may contain abstract method declarations and is therefore assumed to be incomplete. A final class can not be extended. The implementation of an abstract final class could not be completed. The declaration of class C results in a compiler error because a final class may not be listed in the extends clause.  
3a  c  e  f  g  h  l  abstract  final  private  protected  public  static  strictfp  The access modifiers, public, protected and private, can not be applied to a local class. The access modifiers, protected and private, can be applied to member classes but not to top level classes. The public modifier can be applied to a top level class or a member class, but not a local class. The static modifier can be applied to a member class but not a local class or top level class. Extends and implements are keywords but are not modifiers. Synchronized can be applied to a method but not a class. Transient and volatile can be applied to a field but not a class. The strictfp modifier can be applied to a class, interface, or method to guarantee that all float or double operations are processed according to the IEEE 754 standard. Without the strictfp modifier the float or double operations can be processed using the greatest precision available. For example, a 64 bit CPU could process intermediate float operations using 64 rather than only 32 bits. If a class is marked strictfp then all float or double expressions within all nested classes, methods, constructors, static initializers, instance initializers, and variable initializers will also be strictfp.  
4a  c  d  f  A nested class is any class that is declared within the body of another class or interface.  A top level class is a class this is not a nested class.  An inner class is a nested class that is not static.  A named class is any class that is not anonymous.  Every class declared within the body of another class or interface is known as a nested class. If the nested class does not have a name then it is an anonymous class. If the nested class has a name then it is not anonymous. If the nested class has a name and is not declared inside of a block then it is a member class. If the member class is not static then it is an inner class. If the class is not nested then it is a top level class. Chapter 8 of the Java Language Specification defines class declarations. Section 8.1.2 of the JLS defines inner classes. Section 8.5 of the JLS defines member classes. Section 15.9.5 of the JLS defines anonymous class declarations.  
5a  b  c  d  e  f  g  public  protected  private  abstract  static  final  strictfp  A nested class that has a name and is not a local class is a member class. A member class can be static or non-static. A non-static member class is also known as an inner class. All of the class modifiers may be applied to a member class. A member class may also be strictfp, but that information is not required for the exam. The strictfp modifier can be applied to a class, interface, or method to guarantee that all float or double operations are processed according to the IEEE 754 standard. Without the strictfp modifier the float or double operations can be processed using the greatest precision available. For example, a 64 bit CPU could process intermediate float operations using 64 rather than only 32 bits. If a class is marked strictfp then all float or double expressions within all nested classes, methods, constructors, static initializers, instance initializers, and variable initializers will also be strictfp.  
6b  c  An incompletely implemented class must be declared abstract.  A local class can be declared abstract.  An anonymous can not be extended therefore an anonymous class can not be declared abstract. Even a local class can be abstract. An abstract class can not be instantiated. Any class that declares an abstract method must also be abstract. A class can be declared abstract even if it does not declare an abstract method. An abstract class can never be declared final.  
7b  2  An abstract method has no implementation and is not useful until an extending class implements the method. Private methods are not inherited and can not be overridden. If an abstract method is declared private then it can not be implemented in a subclass. Although a method may not be both private and abstract a nested class can be; because another nested class can extend the abstract class and implement any abstract methods.  
8d  4  Methods and fields can share the same name because they are used in different contexts and use different lookup procedures. They can even share the same name with the class in which they are declared. Please note, however, that class names usually begin with an upper case letter while method and field names usually begin with a lower case letter. A nested class can not share the same name with its enclosing class.  
9a  b  c  d  e  f  nested classes  methods  constructors  static initializers  instance initializers  variable initializers  The strictfp modifier can be applied to a class, interface, or method to guarantee that all float or double operations are processed according to the IEEE 754 standard. Without the strictfp modifier the float or double operations can be processed using the greatest precision available. For example, a 64 bit CPU could process intermediate float or double operations using 64 rather than only 32 bits. If a class is marked strictfp then all float or double expressions within all nested classes, methods, constructors, static initializers, instance initializers, and variable initializers will also be strictfp.  
10b  2  The strictfp modifier in a superclass declaration has no impact on an overriding method in a subclass. For that reason, it makes no sense to include the strictfp modifier in an abstract method declaration. By generating a compile time error, the compiler reminds the programmer of the futility of combining the abstract and strictfp modifiers. A class, however, may be both abstract and strictfp. When applied to a class, the strictfp modifier causes all float and double expressions within the class to be strictfp. This implies that all float and double expressions are strictfp in all nested classes, methods, constructors and all static, instance, and variable initializers. The declaration of an abstract method in a strictfp class is entirely legal even though the implementation of the method in a subclass need not be strictfp.  
11g  h  i  7  8  9  The following modifiers can not be applied to a top-level class: private, protected, static, synchronized, transient, volatile. The synchronized modifier can not be applied to any class because it is a method modifier. The modifiers, transient and volatile, can not be applied to any class because they are field modifiers.  
12a  b  c  d  e  f  s1   s2   s3   s4   s5   s6   Class Z is a member class of class A and therefore has access to all of the fields and methods (static, non-static, and private) of class A.  
13a  c  d  e  f  s1   s3   s4   s5   s6   Class Z is a static member class of class B and therefore has access to all of the static fields and methods of class B. However, a static member class does not have access to non-static fields and methods of the enclosing class. Consequently, class Z does not have access to the s2 field of class B.  
14i  j  l  Compiler error at line 11.  Compiler error at line 12.  Compiler error at line 14.  A non-static nested class is called an inner class. An inner class can not declare a static member unless it is a compile time constant. Even though f is final, it does not have a value at compile time and therefore it causes a compilation error. Member variable g also causes a compiler error because it is static. The static initializer of NonStaticInner causes a compiler error because inner classes (i.e. non-static nested classes) can not declare static initializers.  
15d  Compiler error at line 6.  An interface is implicitly static and therefore can not be declared as a member of a non-static nested class.  
16d  G.this.s1  The qualified this expression, ClassName.this.name , can be used to access hidden variables within an enclosing class.  

Copyright © 2002, Dan Chisholm
All rights reserved.
1